package com.usaas.search.utils;

import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.SecureUtil;

public class PasswordUtil {
    public static final String SALT = "searchplatform";

    /**
     * 生成密码
     *
     * @param originPassword
     * @return
     */
    public static String encryptPassword(String originPassword) {
        String md5Pwd = SecureUtil.md5(originPassword);
        return SecureUtil.md5(md5Pwd + SALT);
    }

    /**
     * 获取初始化原始密码
     *
     * @param md5Pwd
     * @return
     */
    public static String getInitialPassword() {
        return encryptPassword("searchplatform123!@#AA@@");
    }

    /**
     * 校验密码
     *
     * @param originPassword
     * @param md5Pwd
     * @return
     */
    public static boolean checkPassword(String originPassword, String md5Pwd) {
        String encryptedPassword = encryptPassword(originPassword);
        return StrUtil.equals(encryptedPassword, md5Pwd);
    }

}
